home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / mmgr / MM_StarTrack.lha / MM / Rexx / MM_ST_CheckWildcard.rexx < prev    next >
OS/2 REXX Batch file  |  1996-05-23  |  2KB  |  124 lines

  1. /* RH 24.06.95 */
  2.  
  3. parse arg addr from to .
  4.  
  5. addr    = strip(addr)
  6. from    = replace(strip(from), '*', '#?')
  7. to        = replace(strip(to),   '*', '#?')
  8.  
  9. if addr='' | from='' | to='' then
  10.     do
  11.     say 'Usage: [RX] CheckWildcard[.rexx] <address> <from-pattern> <to-pattern>'
  12.         say
  13.         exit
  14.   end
  15.  
  16.  
  17. address 'MAILMANAGER'
  18.  
  19.  
  20. if Check_Pattern(from, addr)=0 then
  21.     do
  22.         say
  23.         say 'The from-pattern "'from'" does not match with address "'addr'".'
  24.         say
  25.         exit
  26.     end
  27.  
  28.  
  29. say
  30.  
  31. new = Resolve_Wildcard(addr, from, to)
  32.  
  33. if new=''    then    tmp    = 'Remapping not possible!'
  34. else                        tmp    = addr 'will be remapped to' new
  35.  
  36. say
  37. say tmp
  38. say
  39.  
  40. exit
  41.  
  42.  
  43. Check_Pattern: procedure Expose result
  44.  
  45.   arg pattern, string.0
  46.  
  47.     string.count    = 1
  48.     result.                = 0
  49.  
  50.     MM_SearchInStem 'string' 'result' pattern 'STR'
  51.  
  52.     result                = result.0
  53.  
  54. return result.count>0
  55.  
  56.  
  57. Log: procedure
  58.  
  59.     parse arg text
  60.  
  61.     say text
  62. return
  63.  
  64.  
  65. Replace: procedure
  66.  
  67.     parse arg string,new,old
  68.  
  69.     do while index(string, old)~=0
  70.         interpret "parse var string l '"old"' r"
  71.         string = l || new || r
  72.     end
  73.  
  74. return string
  75.  
  76.  
  77. Resolve_Wildcard: procedure
  78.  
  79.   parse arg address, from, to
  80.  
  81.     parse var address a.1 ':' a.2 '/' a.3 '.' a.4 '@' a.5
  82.     parse var from        f.1 ':' f.2 '/' f.3 '.' f.4 '@' f.5
  83.     parse var to            t.1 ':' t.2 '/' t.3 '.' t.4 '@' t.5
  84.  
  85.     if pos('*', f.5)+pos('*', t.6)>0 then
  86.         do
  87.             say '*** ERROR: Do not use wildcards in the domain-name! ***'
  88.             return ''
  89.         end
  90.  
  91.     do n=1 to 5
  92.         wposf    = pos('*', f.n)
  93.         wpost    = pos('*', t.n)
  94.  
  95.         select
  96.             when wposf=0 & wpost=0    then r.n = t.n
  97.             when wposf>0 & wpost=0    then r.n = f.n
  98.             when wposf>0 & wpost>0    then
  99.                 do
  100.                     dpos    = compare(f.n, t.n)
  101.  
  102.                     if dpos=0    then tmp = ''
  103.                     else                     tmp = substr(t.n, dpos, wpost-dpos)
  104.  
  105.                     r.n        = left(f.n, max(dpos-1, 0)) || tmp || substr(a.n, wposf)
  106.                 end
  107.             otherwise
  108.                 do
  109.                     call Log('*** WILDCARD-ERROR: Unable to resolve' f.n '->' t.n '('from '->' to')')
  110.           call Log('                    Remap NOT possible!')
  111.  
  112.                     do m=1 to 5
  113.                         r.m = a.m
  114.                     end
  115.  
  116.                     leave n
  117.                 end
  118.         end
  119.     end
  120.  
  121. return r.1':'r.2'/'r.3'.'r.4'@'r.5
  122.  
  123.  
  124.